package com.ruoyi.web.controller.douyin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.DyMemberCode;
import com.ruoyi.system.domain.bo.DyAnchorBo;
import com.ruoyi.system.domain.bo.DyCustomerSumBo;
import com.ruoyi.system.domain.bo.DyMemberCodeBo;
import com.ruoyi.system.domain.vo.DyAnchorCustomerVo;
import com.ruoyi.system.domain.vo.DyAnchorVo;
import com.ruoyi.system.domain.vo.DyMemberCodeVo;
import com.ruoyi.system.service.IDyAnchorService;
import com.ruoyi.system.service.IDyMemberCodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 会员码
 *
 * @author ruoyi
 * @date 2024-06-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/member")
public class DyMemberCodeController extends BaseController {

    private final IDyMemberCodeService iDyMemberCodeService;

    /**
     * 查询会员码列表
     */
    @GetMapping("/getMemberCodeList")
    public TableDataInfo<DyMemberCodeVo> getMemberCodeList(DyMemberCodeBo bo, PageQuery pageQuery) {
        return iDyMemberCodeService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询会员码详情
     * @param bo 主键
     */
    @PostMapping("/getMemberCodeInfo")
    @SaIgnore
    public R<DyMemberCodeBo> getMemberCodeInfo(@RequestBody DyMemberCodeBo bo) {
        return R.ok(iDyMemberCodeService.getMemberCodeInfo(bo));
    }

    /**
     * 新增会员码
     */
    @Log(title = "会员码", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/addMemberCode")
    public R<DyMemberCode> addMemberCode(@Validated(AddGroup.class) @RequestBody DyMemberCodeBo bo) {
        return R.ok(iDyMemberCodeService.addMemberCode(bo));
    }

    /**
     * 修改会员码
     */
//    @RepeatSubmit()
//    @PostMapping("/updMemberCode")
//    public R<Void> updMemberCode(@Validated(EditGroup.class) @RequestBody DyMemberCodeBo bo) {
//        return toAjax(iDyMemberCodeService.updMemberCode(bo));
//    }

    /**
     * 删除会员码
     *
     * @param ids 主键串
     */
    @PostMapping("/delMemberCode")
    public R<Void> delMemberCode(@RequestBody List<Long> ids) {
        return toAjax(iDyMemberCodeService.deleteWithValidByIds(ids, true));
    }

    /**
     * 绑定会员码
     *
     * @param bo 主键串
     */
    @PostMapping("/bindMemberCode")
    @SaIgnore
    public R<Void> bindMemberCode(@RequestBody DyMemberCodeBo bo) {
        return toAjax(iDyMemberCodeService.bindMemberCode(bo));
    }

}
